home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / screen_1 / scrnres.frm < prev    next >
Text File  |  1996-12-27  |  3KB  |  136 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Screen Resolution"
  5.    ClientHeight    =   525
  6.    ClientLeft      =   2475
  7.    ClientTop       =   3015
  8.    ClientWidth     =   4170
  9.    Height          =   930
  10.    Left            =   2415
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   525
  15.    ScaleWidth      =   4170
  16.    ShowInTaskbar   =   0   'False
  17.    Top             =   2670
  18.    Width           =   4290
  19.    Begin VB.Label Label2 
  20.       Caption         =   "Label2"
  21.       Height          =   255
  22.       Left            =   2040
  23.       TabIndex        =   1
  24.       Top             =   120
  25.       Width           =   1935
  26.    End
  27.    Begin VB.Label Label1 
  28.       Caption         =   "Your screen resolution is"
  29.       Height          =   255
  30.       Left            =   120
  31.       TabIndex        =   0
  32.       Top             =   120
  33.       Width           =   1815
  34.    End
  35. End
  36. Attribute VB_Name = "Form1"
  37. Attribute VB_Creatable = False
  38. Attribute VB_Exposed = False
  39. Option Explicit
  40.  
  41.  
  42. 'API Declares.
  43. '*************************************************
  44. 'Gets window handle for Desktop window.
  45. Private Declare Function GetDesktopWindow Lib "User32" () As Long
  46.  
  47. 'Retrieve device context.
  48. Private Declare Function GetDC Lib "User32" (ByVal hwnd As Long) As Long
  49.  
  50. 'Get device capabilities.
  51. Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
  52.  
  53. 'Release device context.
  54. Private Declare Function ReleaseDC Lib "User32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
  55.  
  56.  
  57.  
  58. Public Sub DesktopHandle()
  59.     Dim hdesktopwnd
  60.     'Get handle to Desktop.
  61.     hdesktopwnd = GetDesktopWindow()
  62.  
  63. End Sub
  64.  
  65.  
  66. Public Sub DeviceInfo()
  67.     
  68.     Dim DisplayBits
  69.     Dim DisplayPlanes
  70.     Dim DisplayWidth
  71.     Dim DisplayHeight
  72.     Dim RetVal
  73.    'Get display context for desktop.
  74.     hdccaps = GetDC(hdesktopwnd)
  75.     
  76.     'Bits per pixel.
  77.     DisplayBits = GetDeviceCaps(hdccaps, 12)
  78.  
  79.     'Bitplanes.
  80.     DisplayPlanes = GetDeviceCaps(hdccaps, 14)
  81.  
  82.     'Horz. Resolution.
  83.     DisplayWidth = GetDeviceCaps(hdccaps, 8)
  84.  
  85.     'Vert. Resolution.
  86.     DisplayHeight = GetDeviceCaps(hdccaps, 10)
  87.     
  88.     'Release display context.
  89.     RetVal = ReleaseDC(hdesktopwnd, hdccaps)
  90.     'To determine colors:
  91.  
  92. If DisplayBits = 1 Then
  93. If DisplayPlanes = 1 Then
  94.  
  95.     'Running in 1-bit, 2 color mode.
  96.     Label2 = "1-bit/2 colours"
  97.  
  98.     
  99. ElseIf DisplayPlanes = 4 Then
  100.  
  101.     'Running in 4-bit, 16 color mode.
  102.     Label2 = "4-bit/16 colur mode"
  103.  
  104. End If
  105.  
  106. ElseIf DisplayBits = 8 Then
  107.  
  108.     'Running in 8-bit, 256 color mode.
  109.     
  110.     Label2 = "8 bit/256 colours"
  111. ElseIf DisplayBits = 16 Then
  112.  
  113.     'Running in 16-bit, 65000 color mode.
  114.     Label2 = "16 bit/65,000 colours"
  115.  
  116.  
  117. Else
  118.  
  119.     'Running in custom color mode (16million).
  120.     Label2 = "Hmmmm...could be 16,000,000 colurs, or Custom Mode"
  121.  
  122.     
  123. End If
  124.  
  125. End Sub
  126.  
  127.  
  128.  
  129.  
  130. Private Sub Form_Load()
  131. Call DeviceInfo
  132.  
  133. End Sub
  134.  
  135.  
  136.